package com.gin.no_gay_alliance.database.dao;

import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;
import androidx.room.Update;

import com.gin.nga.enums.AccountStatus;
import com.gin.no_gay_alliance.database.entity.NgaUserInfo;

import java.util.List;

/**
 * @author : ginstone
 * @version : v1.0.0
 * @since : 2023/8/1 17:43
 **/
@Dao
public interface NgaUserInfoDao {
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    void add(NgaUserInfo userInfo);

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    void add(List<NgaUserInfo> userInfo);

    @Delete
    int delete(NgaUserInfo userInfo);

    @Query("delete from NgaUserInfo where userId=:userId ")
    int delete(long userId);

    @Update
    int update(NgaUserInfo userInfo);

    @Query("SELECT * FROM NgaUserInfo")
    List<NgaUserInfo> listAll();

    @Query("SELECT * FROM NgaUserInfo where userId=:userId")
    NgaUserInfo get(long userId);

    @Query("SELECT * FROM NgaUserInfo where userId in (:id)")
    List<NgaUserInfo> listById(long[] id);

    @Update
    int update(List<NgaUserInfo> userInfo);

    /**
     * 更新账号状态
     *
     * @param userId    用户ID
     * @param status    状态
     * @param timestamp 时间戳
     */
    @Query("update NgaUserInfo set accountStatus=:status,accountStatusTimestamp=:timestamp where userId=:userId")
    int updateStatus(long userId, AccountStatus status, long timestamp);

    /**
     * 更新IP属地
     *
     * @param userId     用户ID
     * @param ipLocation ip
     * @param timestamp  时间戳
     */
    @Query("update NgaUserInfo set ipLocation=:ipLocation,ipLocationTimestamp=:timestamp where userId=:userId")
    int updateIpLocation(long userId, String ipLocation, long timestamp);


}
